﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;
using Zocono.WMS.Infrastructure.BaseRepository;

namespace Zocono.WCS.Infrastructure.Repository
{
    public class EquipmentLayoutTypeRepository : BaseRepository<EquipmentLayoutTypeInfo>, IEquipmentLayoutTypeRepository
    {
        public EquipmentLayoutTypeRepository(SqlSugarClient context = null) : base(context)
        {

        }

        public async Task<PageDto<EquipmentLayoutTypeInfoDto>> GetEquipmentLayoutTypeAsync(Expression<Func<EquipmentLayoutTypeInfo, EquipmentTypeInfo, bool>> exp, PageModel page)
        {
            PageDto<EquipmentLayoutTypeInfoDto> pageDto = new PageDto<EquipmentLayoutTypeInfoDto>();
            RefAsync<int> totalNumber = 0;
            var result = await Context.Queryable<EquipmentLayoutTypeInfo, EquipmentTypeInfo>((a, b) => new JoinQueryInfos(
                JoinType.Inner, a.EquipmentTypeID == b.ID))
                .Where(exp)
                .Select((a, b) => new EquipmentLayoutTypeInfoDto
                {
                    ID = a.ID,
                    EquipmentTypeID = a.EquipmentTypeID,
                    TypeCode = a.TypeCode,
                    TypeName = a.TypeName,
                    EquipmentTypeName = b.TypeName

                }).ToPageListAsync(page.PageIndex, page.PageSize, totalNumber);
            pageDto.Result = result;
            pageDto.Total = totalNumber;
            return pageDto;
        }
    }
}
